package cn.bytecollege.controller;

import cn.bytecollege.constant.Resource;
import cn.bytecollege.entity.Page;
import cn.bytecollege.entity.Vip;
import cn.bytecollege.service.VipService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * author Mr.East
 */
@WebServlet(name = "VipListController",value = "/vipList")
public class VipListController extends HttpServlet {
    private VipService vipService = null;
    public VipListController(){
        vipService = new VipService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String index = request.getParameter("index");
        String size = request.getParameter("size");
        Integer pageIndex = (index==null)?1:Integer.valueOf(index);
        Integer pageSize = (size==null)?5:Integer.valueOf(size);
        Page<Vip> page = vipService.findByPage(pageIndex,pageSize);
        request.setAttribute("page",page);
        request.getRequestDispatcher(Resource.PAGE_LOCATION + "/vipList.jsp")
                .forward(request,response);
    }
}
